package com.wly.utils
{
	import com.wly.datapool.define.GlobalDefine;

	public class Func
	{
		//返回改单元格的左上角位置
		static public function caculatePos(cellIndex:int):MyPoint
		{
			var ix:int = cellIndex%GlobalDefine.MAP_CELL_WIDTH_NUM;
			var iy:int = cellIndex/GlobalDefine.MAP_CELL_WIDTH_NUM;
			var pos:MyPoint = new MyPoint;
			pos.x = ix*GlobalDefine.CELL_WIDTH;
			pos.y = iy*GlobalDefine.CELL_HEIGHT;
			return pos;
		}
		
		//计算单元格下面中间的位置 也就是立足点
		static public function caculateCellPos(cellIndex:int):MyPoint
		{
			var ix:int = cellIndex%GlobalDefine.MAP_CELL_WIDTH_NUM;
			var iy:int = cellIndex/GlobalDefine.MAP_CELL_WIDTH_NUM;
			var pos:MyPoint = new MyPoint;
			pos.x = ix*GlobalDefine.CELL_WIDTH + GlobalDefine.CELL_WIDTH/2;
			pos.y = (iy+1)*GlobalDefine.CELL_HEIGHT;
			
			return pos;
		}
		
		static public function caculateCellIndex(pos:MyPoint):int
		{
			var x:int;
			var y:int;
			
			if(!pos)
			{
				return 0;
			}
			
			x = pos.x/GlobalDefine.CELL_WIDTH;
			y = pos.y/GlobalDefine.CELL_HEIGHT;
			
			return y*GlobalDefine.MAP_CELL_WIDTH_NUM+x;
		}
	}
}